function addEvent(dom, event, fn, remove) {
  if (typeof dom === 'string') {
    dom = document.querySelectorAll(dom)
  }
  if (dom.length) {
    for (var index = 0; index < dom.length; index++) {
      ;(function() {
        var i = index
        var callback = function(e) {
          fn(e, i)
        }
        dom[index].addEventListener(event, callback)
        if (remove) dom.removeEventListener(event, callback)
      })()
    }
  } else {
    dom.addEventListener(event, fn)
    if (remove) dom.removeEventListener(event, fn)
  }
}

function addClass(dom, cName) {
  if (dom.length) {
    for (var index = 0; index < dom.length; index++) {
      _addClass(dom[index], cName)
    }
  } else {
    _addClass(dom, cName)
  }
}

function removeClass(dom, cName) {
  if (dom.length) {
    for (var index = 0; index < dom.length; index++) {
      _removeClass(dom[index], cName)
    }
  } else {
    _removeClass(dom, cName)
  }
}

function _hasClass(elements, cName) {
  return !!elements.className.match(new RegExp('(\\s|^)' + cName + '(\\s|$)'))
}

function _addClass(elements, cName) {
  if (!_hasClass(elements, cName)) {
    elements.className += ' ' + cName
  }
}

function _removeClass(elements, cName) {
  if (_hasClass(elements, cName)) {
    elements.className = elements.className.replace(
      new RegExp('(\\s+|^)' + cName + '(\\s+|$)'),
      ' '
    )
  }
}
